import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getDictTree } from '@/api/api'
import { Sm4encrypt, Sm4Dncrypt } from '@/utils/encryption.js'

import {sessionMemory} from '@/utils/sessionMemory'

export const dictStore = defineStore('dictCode', () => {
  const dict = ref(sessionMemory.getItem('dictTree'))
  /* 获取字典信息*/
  const getDict = async () => {
    const res = await getDictTree()
    if (res.status === 200) {
      // dict.push(... res.data)
      dict.value = res.data
      sessionMemory.setItem('dictTree',res.data)
      // window.sessionStorage.setItem(Sm4encrypt("dictTree"), Sm4encrypt(JSON.stringify(dict)))
    }
    return true
  }
  const clearDict = ()=>{
    dict.value = []
  }


  return {
    getDict,
    clearDict,
    dict
  }
})
